const query = require('../utils/DB')
class menuModel {
	// 获取广告列表
	static async getMenuList(
		nowPage = 1,
		pageSize = 10
	) {
		let start = (nowPage - 1) * pageSize
		let listCount = await query(`select count(*) as num from menu`)
		let list =await query(
			`select * from menu  limit ${start},${pageSize}`)
		return {
			count: listCount[0].num,
			list: list
		}
	}
	// 添加广告
	static addMenu(name, path, openurl, status) {
		return query(`INSERT INTO menu(name, path, openurl, status) VALUES ('${name}', '${path}', '${openurl}', ${status})`)
	}

	// 修改广告
	static editMenu(id, name, path, openurl, status) {
		return query(`UPDATE menu SET openurl = '${openurl}',name='${name}',path='${path}',status=${status} WHERE id = ${id}`)
	}

	// 删除广告
	static delMenu(id) {
		return query(`delete from menu where id=${id}`)
	}


}
module.exports = menuModel
